/**
 * 
 */
package org.softTank.BC.manager;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.softTank.BC.manager.util.ServiceParser;
import org.softTank.BC.rs.bean.ServiceBean;

/**
 * This class manages different ways of getting Services information. If
 * necessary, edit this class to add some ways of getting data.
 * 
 * @author Yuzone
 * 
 */
public class ServiceManager {

	protected Logger logger;
	protected ServiceParser serviceParser;

	public ServiceManager() {
		logger = Logger.getLogger(this.getClass());
	}

	public List<ServiceBean> getDataServices(String category) {
		if (serviceParser == null) {
			serviceParser = new ServiceParser();
		}
		List<ServiceBean> sbList = serviceParser.getServices(category);
		if (sbList == null) {
			logger.debug("No Services found under this category!");
			return new ArrayList<ServiceBean>();
		}

		return sbList;
	}

	public List<ServiceBean> getFunctionServices(String category) {
		List<ServiceBean> sbList = getDataServices(category);
		for (ServiceBean sb : sbList) {
			sb.setIsBranch("true");
		}

		return sbList;
	}

	public ServiceBean getService(String serviceID) {
		if (serviceParser == null) {
			serviceParser = new ServiceParser();
		}
		ServiceBean sb = serviceParser.getService(serviceID);
		if (sb == null) {
			logger.debug("No such service is found!");
			return null;
		}
		sb.setIsBranch("true");

		return sb;
	}

	public ServiceParser getServiceParser() {
		return serviceParser;
	}

	public void setServiceParser(ServiceParser serviceParser) {
		this.serviceParser = serviceParser;
	}
}
